In [1]:
pip install plotly
Requirement already satisfied: plotly in c:\users\snaha\anaconda3\lib\site-packages (5.10.0)Note: you may need to restart the kernel to use updated packages.

Requirement already satisfied: tenacity>=6.2.0 in c:\users\snaha\anaconda3\lib\site-packages (from plotly) (8.0.1)
In [2]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import plotly.express as px
import plotly.graph_objects as go
In [3]:
data = pd.read_csv("House_Rent_Dataset.csv")
print(data.head())
    Posted On  BHK   Rent  Size            Floor    Area Type  \
0  2022-05-18    2  10000  1100  Ground out of 2   Super Area   
1  2022-05-13    2  20000   800       1 out of 3   Super Area   
2  2022-05-16    2  17000  1000       1 out of 3   Super Area   
3  2022-07-04    2  10000   800       1 out of 2   Super Area   
4  2022-05-09    2   7500   850       1 out of 2  Carpet Area   

              Area Locality     City Furnishing Status  Tenant Preferred  \
0                    Bandel  Kolkata       Unfurnished  Bachelors/Family   
1  Phool Bagan, Kankurgachi  Kolkata    Semi-Furnished  Bachelors/Family   
2   Salt Lake City Sector 2  Kolkata    Semi-Furnished  Bachelors/Family   
3               Dumdum Park  Kolkata       Unfurnished  Bachelors/Family   
4             South Dum Dum  Kolkata       Unfurnished         Bachelors   

   Bathroom Point of Contact  
0         2    Contact Owner  
1         1    Contact Owner  
2         1    Contact Owner  
3         1    Contact Owner  
4         1    Contact Owner  
In [4]:
data
Out[4]:
Posted On BHK Rent Size Floor Area Type Area Locality City Furnishing Status Tenant Preferred Bathroom Point of Contact
0 2022-05-18 2 10000 1100 Ground out of 2 Super Area Bandel Kolkata Unfurnished Bachelors/Family 2 Contact Owner
1 2022-05-13 2 20000 800 1 out of 3 Super Area Phool Bagan, Kankurgachi Kolkata Semi-Furnished Bachelors/Family 1 Contact Owner
2 2022-05-16 2 17000 1000 1 out of 3 Super Area Salt Lake City Sector 2 Kolkata Semi-Furnished Bachelors/Family 1 Contact Owner
3 2022-07-04 2 10000 800 1 out of 2 Super Area Dumdum Park Kolkata Unfurnished Bachelors/Family 1 Contact Owner
4 2022-05-09 2 7500 850 1 out of 2 Carpet Area South Dum Dum Kolkata Unfurnished Bachelors 1 Contact Owner
... ... ... ... ... ... ... ... ... ... ... ... ...
4741 2022-05-18 2 15000 1000 3 out of 5 Carpet Area Bandam Kommu Hyderabad Semi-Furnished Bachelors/Family 2 Contact Owner
4742 2022-05-15 3 29000 2000 1 out of 4 Super Area Manikonda, Hyderabad Hyderabad Semi-Furnished Bachelors/Family 3 Contact Owner
4743 2022-07-10 3 35000 1750 3 out of 5 Carpet Area Himayath Nagar, NH 7 Hyderabad Semi-Furnished Bachelors/Family 3 Contact Agent
4744 2022-07-06 3 45000 1500 23 out of 34 Carpet Area Gachibowli Hyderabad Semi-Furnished Family 2 Contact Agent
4745 2022-05-04 2 15000 1000 4 out of 5 Carpet Area Suchitra Circle Hyderabad Unfurnished Bachelors 2 Contact Owner

4746 rows × 12 columns

In [5]:
print(data.isnull().sum())
Posted On            0
BHK                  0
Rent                 0
Size                 0
Floor                0
Area Type            0
Area Locality        0
City                 0
Furnishing Status    0
Tenant Preferred     0
Bathroom             0
Point of Contact     0
dtype: int64
In [6]:
print(data.describe())
               BHK          Rent         Size     Bathroom
count  4746.000000  4.746000e+03  4746.000000  4746.000000
mean      2.083860  3.499345e+04   967.490729     1.965866
std       0.832256  7.810641e+04   634.202328     0.884532
min       1.000000  1.200000e+03    10.000000     1.000000
25%       2.000000  1.000000e+04   550.000000     1.000000
50%       2.000000  1.600000e+04   850.000000     2.000000
75%       3.000000  3.300000e+04  1200.000000     2.000000
max       6.000000  3.500000e+06  8000.000000    10.000000
In [7]:
print(f"Mean Rent: {data.Rent.mean()}")
print(f"Median Rent: {data.Rent.median()}")
print(f"Highest Rent: {data.Rent.max()}")
print(f"Lowest Rent: {data.Rent.min()}")
Mean Rent: 34993.45132743363
Median Rent: 16000.0
Highest Rent: 3500000
Lowest Rent: 1200
In [8]:
figure = px.bar(data, x=data["City"], 
                y = data["Rent"], 
                color = data["BHK"],
            title="Rent in Different Cities According to BHK")
figure.show()
In [9]:
figure = px.bar(data, x=data["City"], 
                y = data["Rent"], 
                color = data["Area Type"],
            title="Rent in Different Cities According to Area Type")
figure.show()
In [10]:
figure = px.bar(data, x=data["City"], 
                y = data["Rent"], 
                color = data["Furnishing Status"],
            title="Rent in Different Cities According to Furnishing Status")
figure.show()
In [11]:
figure = px.bar(data, x=data["City"], 
                y = data["Rent"], 
                color = data["Size"],
            title="Rent in Different Cities According to Size")
figure.show()
In [12]:
cities = data["City"].value_counts()
label = cities.index
counts = cities.values
colors = ['gold','lightgreen']

fig = go.Figure(data=[go.Pie(labels=label, values=counts, hole=0.5)])
fig.update_layout(title_text='Number of Houses Available for Rent')
fig.update_traces(hoverinfo='label+percent', textinfo='value', textfont_size=30,
                  marker=dict(colors=colors, line=dict(color='black', width=3)))
fig.show()
In [13]:
# Preference of Tenant
tenant = data["Tenant Preferred"].value_counts()
label = tenant.index
counts = tenant.values
colors = ['gold','lightgreen']

fig = go.Figure(data=[go.Pie(labels=label, values=counts, hole=0.5)])
fig.update_layout(title_text='Preference of Tenant in India')
fig.update_traces(hoverinfo='label+percent', textinfo='value', textfont_size=30,
                  marker=dict(colors=colors, line=dict(color='black', width=3)))
fig.show()
In [14]:
data["Area Type"] = data["Area Type"].map({"Super Area": 1, 
                                           "Carpet Area": 2, 
                                           "Built Area": 3})
data["City"] = data["City"].map({"Mumbai": 4000, "Chennai": 6000, 
                                 "Bangalore": 5600, "Hyderabad": 5000, 
                                 "Delhi": 1100, "Kolkata": 7000})
data["Furnishing Status"] = data["Furnishing Status"].map({"Unfurnished": 0, 
                                                           "Semi-Furnished": 1, 
                                                           "Furnished": 2})
data["Tenant Preferred"] = data["Tenant Preferred"].map({"Bachelors/Family": 2, 
                                                         "Bachelors": 1, 
                                                         "Family": 3})
print(data.head())
    Posted On  BHK   Rent  Size            Floor  Area Type  \
0  2022-05-18    2  10000  1100  Ground out of 2          1   
1  2022-05-13    2  20000   800       1 out of 3          1   
2  2022-05-16    2  17000  1000       1 out of 3          1   
3  2022-07-04    2  10000   800       1 out of 2          1   
4  2022-05-09    2   7500   850       1 out of 2          2   

              Area Locality  City  Furnishing Status  Tenant Preferred  \
0                    Bandel  7000                  0                 2   
1  Phool Bagan, Kankurgachi  7000                  1                 2   
2   Salt Lake City Sector 2  7000                  1                 2   
3               Dumdum Park  7000                  0                 2   
4             South Dum Dum  7000                  0                 1   

   Bathroom Point of Contact  
0         2    Contact Owner  
1         1    Contact Owner  
2         1    Contact Owner  
3         1    Contact Owner  
4         1    Contact Owner  
In [15]:
#splitting data
from sklearn.model_selection import train_test_split
x = np.array(data[["BHK", "Size", "Area Type", "City", 
                   "Furnishing Status", "Tenant Preferred", 
                   "Bathroom"]])
y = np.array(data[["Rent"]])

xtrain, xtest, ytrain, ytest = train_test_split(x, y, 
                                                test_size=0.10, 
                                                random_state=42)
In [16]:
from keras.models import Sequential
from keras.layers import Dense, LSTM
model = Sequential()
model.add(LSTM(128, return_sequences=True, 
               input_shape= (xtrain.shape[1], 1)))
model.add(LSTM(64, return_sequences=False))
model.add(Dense(25))
model.add(Dense(1))
model.summary()
Model: "sequential"
_________________________________________________________________
 Layer (type)                Output Shape              Param #   
=================================================================
 lstm (LSTM)                 (None, 7, 128)            66560     
                                                                 
 lstm_1 (LSTM)               (None, 64)                49408     
                                                                 
 dense (Dense)               (None, 25)                1625      
                                                                 
 dense_1 (Dense)             (None, 1)                 26        
                                                                 
=================================================================
Total params: 117,619
Trainable params: 117,619
Non-trainable params: 0
_________________________________________________________________
In [17]:
model.compile(optimizer='adam', loss='mean_squared_error')
model.fit(xtrain, ytrain, batch_size=1, epochs=21)
Epoch 1/21
4271/4271 [==============================] - 19s 4ms/step - loss: 7056415232.0000
Epoch 2/21
4271/4271 [==============================] - 16s 4ms/step - loss: 6473784320.0000
Epoch 3/21
4271/4271 [==============================] - 18s 4ms/step - loss: 6183408128.0000
Epoch 4/21
4271/4271 [==============================] - 16s 4ms/step - loss: 5924621312.0000
Epoch 5/21
4271/4271 [==============================] - 15s 4ms/step - loss: 5856545280.0000
Epoch 6/21
4271/4271 [==============================] - 15s 4ms/step - loss: 5658317312.0000
Epoch 7/21
4271/4271 [==============================] - 15s 4ms/step - loss: 5590473728.0000
Epoch 8/21
4271/4271 [==============================] - 15s 4ms/step - loss: 5536091136.0000
Epoch 9/21
4271/4271 [==============================] - 15s 4ms/step - loss: 5486078464.0000
Epoch 10/21
4271/4271 [==============================] - 15s 4ms/step - loss: 5423145984.0000
Epoch 11/21
4271/4271 [==============================] - 15s 4ms/step - loss: 5358457856.0000
Epoch 12/21
4271/4271 [==============================] - 16s 4ms/step - loss: 5435250176.0000
Epoch 13/21
4271/4271 [==============================] - 17s 4ms/step - loss: 5274282496.0000
Epoch 14/21
4271/4271 [==============================] - 17s 4ms/step - loss: 5219998208.0000
Epoch 15/21
4271/4271 [==============================] - 17s 4ms/step - loss: 5081291264.0000
Epoch 16/21
4271/4271 [==============================] - 17s 4ms/step - loss: 5033412608.0000
Epoch 17/21
4271/4271 [==============================] - 17s 4ms/step - loss: 4899162624.0000
Epoch 18/21
4271/4271 [==============================] - 18s 4ms/step - loss: 4930206208.0000
Epoch 19/21
4271/4271 [==============================] - 17s 4ms/step - loss: 4875352576.0000
Epoch 20/21
4271/4271 [==============================] - 17s 4ms/step - loss: 4823479808.0000
Epoch 21/21
4271/4271 [==============================] - 17s 4ms/step - loss: 4802553344.0000
Out[17]:
<keras.callbacks.History at 0x247e31b1e50>
In [18]:
print("Enter House Details to Predict Rent")
a = int(input("Number of BHK: "))
b = int(input("Size of the House: "))
c = int(input("Area Type (Super Area = 1, Carpet Area = 2, Built Area = 3): "))
d = int(input("Pin Code of the City: "))
e = int(input("Furnishing Status of the House (Unfurnished = 0, Semi-Furnished = 1, Furnished = 2): "))
f = int(input("Tenant Type (Bachelors = 1, Bachelors/Family = 2, Only Family = 3): "))
g = int(input("Number of bathrooms: "))
features = np.array([[a, b, c, d, e, f, g]])
print("Predicted House Price = ", model.predict(features))
Enter House Details to Predict Rent
Number of BHK: 2
Size of the House: 2000
Area Type (Super Area = 1, Carpet Area = 2, Built Area = 3): 2
Pin Code of the City: 700124
Furnishing Status of the House (Unfurnished = 0, Semi-Furnished = 1, Furnished = 2): 2
Tenant Type (Bachelors = 1, Bachelors/Family = 2, Only Family = 3): 2
Number of bathrooms: 2
Predicted House Price =  [[27172.615]]
In [ ]: